<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011   Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012   Daniel Munn  <dan.munn@munnster.co.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.%>

<% html_title(l(:dmsf)) %>

<div class="contextual">
  <% if User.current.allowed_to?(:folder_manipulation, @project) && params[:action] == 'edit' %>
    <% unless @folder.locked? %>
       <%= link_to(l(:button_lock),
          lock_dmsf_path(:id => @project, :folder_id => @folder),
          :title => l(:title_lock_file),
          :class => 'icon icon-dmsf-lock') %>  
      <% if @folder.notification %>              
          <%= link_to(l(:label_notifications_off),
           notify_deactivate_dmsf_path(:id => @project, :folder_id => @folder),
            :title => l(:title_notifications_active_deactivate),
            :class => 'icon icon-notification-on') %>
        <% else %>              
          <%= link_to(l(:label_notifications_on),
            notify_activate_dmsf_path(:id => @project, :folder_id => @folder),
            :title => l(:title_notifications_not_active_activate),
            :class => 'icon icon-notification-off') %>
        <% end %>      
      <%= link_to(l(:label_link_to), 
        new_dmsf_link_path(:project_id => @project.id, :dmsf_folder_id => @folder.id, :type => 'link_to'),
        :title => l(:title_create_link), 
        :class => 'icon icon-link') %>
      <%= link_to(l(:button_copy), copy_folder_path(:id => @folder),
        :title => l(:title_copy), :class => 'icon icon-copy') %>      
      <%= link_to(l(:button_delete),
        delete_dmsf_path(:id => @project, :folder_id => @folder),
        :data => {:confirm => l(:text_are_you_sure)},            
        :title => l(:title_delete),
        :class => 'icon icon-del') %> 
    <% else %>
      <% if (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) && @folder.unlockable? %>
        <%= link_to(l(:button_unlock),
          unlock_dmsf_path(:id => @project, :folder_id => @folder),
            :title => l(:title_unlock_file),
            :class => 'icon icon-dmsf-unlock')%>
      <% end %>        
    <% end %>   
  <% end %>
</div>

<% create = @pathfolder == @parent %>
<%= render(:partial => 'path', :locals => {:folder => @pathfolder, :filename => create ? l(:heading_new_folder) : nil}) %>  

<%= form_for(@folder, :url => {:action => create ? 'create' : 'save', :id => @project, :folder_id => @folder, :parent_id => @parent},
  :html => {:method=>:post}) do |f| %>
  <%= error_messages_for(@folder) %>
  <div class="box dmsf_detail">
    <div class="clear">
      <div class="splitcontentleft">
        <p>
          <%= label_tag('dmsf_folder_title', "#{l(:label_title)}:") %>
          <%= f.text_field(:title, :size => '32', :required => true) %>
        </p>
      </div>
      <div class="splitcontentright">
        <p>
          <%= label_tag('', "#{l(:field_folder)}:") %>
          <%= f.select(:dmsf_folder_id, 
            options_for_select(DmsfFolder.directory_tree(@project, @folder), 	
            :selected => @parent? @parent.id : (@pathfolder.id if @pathfolder)))                                                  
          %>				
        </p>
      </div>
    </div>
    <p class="no-ident">
      <%= label_tag('dmsf_folder_description', "#{l(:label_description)}:") %>
    </p>
    <div class="wiki data clear">
      <%= f.text_area(:description, :rows => 15, :class => 'wiki-edit') %>
    </div>
    <% values = @folder ? @folder.custom_field_values : @parent ? @parent.custom_field_values : DmsfFolder.new(:project => @project).custom_field_values %>
    <% values.each do |value| %>
      <p><%= custom_field_tag_with_label(:dmsf_folder, value) %></p>
    <% end %>
  </div>
  <%= submit_tag(create ? l(:submit_create) : l(:submit_save)) %>
<% end %>

<%= wikitoolbar_for 'dmsf_folder_description' %>
